package pl.edu.agh.admin.core;

import java.util.Calendar;
import java.util.List;
import java.util.Map;

import pl.edu.agh.admin.api.CronFromatException;
import pl.edu.agh.admin.api.CronParameter;
import pl.edu.agh.admin.api.Task;
import pl.edu.agh.admin.api.User;

public class TaskImpl implements Task {

	private User user;
	private String cronLine;
	private Map<CronParameter, String> params;
	
	public TaskImpl(String cronLine, User user, Map<CronParameter, String> params){
		this.user = user;
		this.params = params;
		this.cronLine = cronLine;		
	}
	
	@Override
	public Map<CronParameter, String> getParameters() {
		return params;
	}

	@Override
	public String getCommand() {
		return CRONParser.getCommand(cronLine);
	}

	@Override
	public String getPlainCron() {
		return CRONParser.getPlainCron(cronLine);
	}

	@Override
	public List<Calendar> getAllMomentsOfExecution(Calendar until) {
		return CRONParser.getAllMomentsOfExecution(CRONParser.getPlainCron(cronLine) ,until);
	}

	@Override
	public User getUser() {
		return user;
	}

	@Override
	public int getNumberOfExecutions(Calendar until) {
		return CRONParser.getNumberOfExecutions(cronLine, until);
	}

	@Override	
	public Calendar getNextTimeOfExecution() {
		return CRONParser.getNextTimeOfExecution(cronLine);
	}

	public String toString(){
		return "["  +user.getName() +"]: " + cronLine;
	}

	@Override
	public String getCron() 
	{
		return "1 4 8 8";
	}
}
